package com.lovo.roomProject.classManager.dao.impl;

import com.lovo.roomProject.classManager.dao.ClassDAO;
import com.lovo.roomProject.dao.BaseDAO;
import com.lovo.roomProject.pojo.ClaszDO;

import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

public class ClassDAOImpl extends BaseDAO implements ClassDAO {
    @Override
    public List listClass() {
        this.getConnection();
        String sql = "select * from t_class";
        List list = new ArrayList();
        try {
            preparedStatement = con.prepareStatement(sql);
            rs = preparedStatement.executeQuery();
            while (rs.next()) {
                ClaszDO clasz = new ClaszDO();
                clasz.setId(rs.getInt("c_id"));
                clasz.setName(rs.getString("c_name"));
                clasz.setDate(LocalDate.parse(rs.getString("c_create_date")));
                clasz.setTeacher(rs.getString("c_teacher"));
                list.add(clasz);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            close(con, preparedStatement, rs);
        }
        return list;
    }
}
